package com.itheima;

import com.itheima.domain.Classes;
import com.itheima.domain.Student;
import com.itheima.domain.Student01;
import com.itheima.mapper.ManyToManyMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class OneToManyMapper {
    @Test
    public void selectAll() throws IOException {
        InputStream is = Resources.getResourceAsStream("MybatisConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = build.openSession();
        com.itheima.mapper.OneToManyMapper mapper = sqlSession.getMapper(com.itheima.mapper.OneToManyMapper.class);
        List<Classes> classes = mapper.selectAll();
        for (Classes aClass : classes) {
            System.out.println(aClass);
        }
    }
    @Test
    public void selectManyAll() throws IOException {
        InputStream is = Resources.getResourceAsStream("MybatisConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = build.openSession();
        ManyToManyMapper mapper = sqlSession.getMapper(ManyToManyMapper.class);
        List<Student01> students = mapper.selectManyAll();
        for (Student01 student : students) {
            System.out.println(student);
        }

    }
}
